/**
 * @date 2006-3-21 14:29:02
 *
 */
package org.nanhill.xmlro.sro.spring;

import java.lang.reflect.Method;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nanhill.xmlro.sro.SroHelper;
import org.nanhill.xmlro.sro.config.ActionConfig;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author alin [xalinx at gmail dot com]
 * 
 */
public class SroActionExporter extends SroAbstractControllerExporter {

	private ActionConfig globalConfig;

	public ActionConfig getGlobalConfig() {
		return globalConfig;
	}

	public void setGlobalConfig(ActionConfig globalConfig) {
		this.globalConfig = globalConfig;
	}

	private Map<String, Object> actionMap;

	public Map<String, Object> getActionMap() {
		return actionMap;
	}

	public void setActionMap(Map<String, Object> actionMap) {
		this.actionMap = actionMap;
	}

	private Map<String, ActionConfig> configMap;

	public Map<String, ActionConfig> getConfigMap() {
		return configMap;
	}

	public void setConfigMap(Map<String, ActionConfig> configMap) {
		this.configMap = configMap;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.xmlro.spring.AbstractXmlroControllerExporter#getCallService(javax.servlet.http.HttpServletRequest)
	 */
	@Override
	protected Object getCallService(HttpServletRequest request)
			throws Exception {
		// get action name
		String actionName = request.getParameter(SroHelper.SRO_METHOD);
		if (null == actionName) {
			throw new ServletException(
					"Http request must contains a parameter ["
							+ SroHelper.SRO_METHOD + "] to call server action!");
		}
		if (!this.actionMap.containsKey(actionName)) {
			throw new Exception("Sro remote call action name: " + actionName
					+ " not exist!");
		}
		Object action = this.actionMap.get(actionName);
		return action;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.xmlro.spring.AbstractXmlroControllerExporter#getCallMethod(javax.servlet.http.HttpServletRequest,
	 *      java.lang.Object)
	 */
	@Override
	protected Method getCallMethod(HttpServletRequest request, Object service)
			throws Exception {
		return null;
	}

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

}
